import React from 'react';
import axios from 'axios';
import { HashRouter as Router, Route, Link, NavLink, Switch } from 'react-router-dom'
import './App.css';
import 'antd/dist/antd.css';
import routes from './routes.config';
import ShouYe from './ShouYe.js'

class App extends React.Component {
	constructor() {
		super();
		this.state = { name: 'fanxiaopa', date: new Date() }
	}

	update = () => {
		this.setState({
			date: new Date()
		})
	}

	componentDidMount() {
		// setInterval(this.update,1000)
		axios.defaults.baseURL="http://localhost:3000";
		window.axios = axios;
	}

	renderRoutes = (routes) => {
		return routes.map((route, index) => {
			if (route.children) {
				return (
					<Route key={index} path={route.path}>
						{ this.renderRoutes(route.children) }
					</Route>
				)
			} else {
				return (
					<Route key={index} path={route.path} component={route.component} />
				)
			}
			
		})
	}

	render() {
		return (
			<div className="App">
				<Router>
					<Switch>
						<Route path='/' exact component={ShouYe} />
						{ this.renderRoutes(routes) }
					</Switch>
				</Router>
			</div>
		);
	}
}

export default App;
